<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用量查询</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript" src="/static/js/date.js"></script>
    <script type="text/javascript">

        var url;
        //禁止整体该页面的右键弹出html相关,不阻碍easyui右键
        $(function () {
            $(document).bind('contextmenu', function (e) {
                e.preventDefault();
                $('#tree-0').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
        });
        //项目列表选择
        function openProjListChoose() {
            $("#projList").dialog("open").dialog("setTitle", "进入项目选择");
            $("#projTree").tree({
                url: '/admin/project/loadProjectTree',
                onLoadSuccess: function (node, data) {
                    $("#tree").tree('expandAll');
                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    var rootNodes = $("#tree").tree('getRoots');
                    for (var i = 0; i < rootNodes.length; i++) {
                        var theNode = $("#tree").tree('find', rootNodes[i].id);
                        $("#tree").tree('uncheck', theNode.target);
                    }
                    $("#tree").tree('select', node.target);
                    if (node.attributes.state == 2) {
                        $("#tree-2").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else if (node.attributes.state == 1) {
                        $("#tree-1").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else {
                        $('#tree-0').menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    }

                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#projNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#projNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadDataGrid();
        }

        //加载项目数据表格
        function loadDataGrid() {
            $("#projNameList").datagrid({
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#projId").val(row.id);
                    $("#projName").val(row.xiangmumingcheng);
                    $("#projList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        //加载部门tree类别 (领料单位)
        function openDeptListChoose() {
            $("#deptList").dialog("open").dialog("setTitle", "选择发料单位");
            $("#deptTree").tree({
                url: '/admin/bumen/loadBumenTree',
                onLoadSuccess: function (node, data) {
                    $("#deptTree").tree('expandAll');
                },
                onDblClick: function (node) {

                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#deptNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#deptNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadDeptDataGrid();
        }

        //加载部门数据表格
        function loadDeptDataGrid() {
            $("#deptNameList").datagrid({
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#deptId").val(row.id);
                    $("#deptName").val(row.bumenmingcheng);
                    $("#deptList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                },
            });
        }

        $(document).ready(function () {
            $("#s_btime").datebox("setValue", genLastMonthDayStr()); // 设置上个月日期
            $("#s_etime").datebox("setValue", genTodayStr()); // 设置当前日期
            search();
        });

        //搜索用量 根据项目.库房,物料类别id,开始结束时间(在物料出库单里)
        function search() {
            $('#dg').datagrid('loadData', {total: 0, rows: []});
            var xiangmumingcheng = $("#projName").val(); //项目名称
            var lingliaodanwei = $("#deptName").val(); //出库库房
            var chukudanhao = $("#chukudanhaoinput").val(); //对应出库单号
            var mingchengguige = $("#mingchengguige").val();
            var o_id = $("#o_id").val(); //物料类别id
            var s_btime = $("#s_btime").datebox("getValue");
            var s_etime = $("#s_etime").datebox("getValue");

            $("#dg").datagrid({
                url: '/admin/chukuzhixing/getSelective',
                queryParams: {
                    // wuliaotuikudanhao:wuliaotuikudanhao,
                    duiyingchukudanhao:chukudanhao,
                    xiangmumingcheng:xiangmumingcheng,
                    lingliaodanwei:lingliaodanwei,
                    mingchengguige:mingchengguige,
                    o_id:o_id,
                    s_btime:s_btime,
                    s_etime:s_etime
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        function chooseGoodsType() {
            $("#dlg2").dialog("open").dialog("setTitle", "选择物料类别");
            $("#typeTree").tree({
                url: '/admin/wuliaoTree/loadWuliaoTree',
                onLoadSuccess: function (node, data) {
                    var rootNode = $("#typeTree").tree('getRoot');
                    $("#typeTree").tree('expand', rootNode.target);
                }
            });
        }

        //保存物料分类选择
        function saveGoodsTypeChoose() {
            var node = $('#typeTree').tree('getSelected'); // 获取选中节点
            console.log("o_id:"+node.id);
            $("#o_id").val(node.id);
            $("#typeName").val(node.text);
            $("#dlg2").dialog("close");
        }

        function closeGoodsTypeChooseDialog() {
            $("#dlg2").dialog("close");
        }

        //查询项目
        function searchProj() {
            $("#projNameList").datagrid('load', {
                "xiangmumingcheng": $("#projSearch").val()
            });
        }


        // 查询部门
        function searchDept() {
            $("#deptNameList").datagrid('load', {
                "bumenmingcheng": $("#deptSearch").val()
            })
        }

    </script>
</head>
<body style="margin: 1px">

<table id="dg" title="用量查询" class="easyui-datagrid" fit=true
       url="/admin/chukuzhixing/getSelective"
       fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
       toolbar="#tb">
    <thead>
    <tr>
        <th field="id" width="20" align="center" hidden="true" sortable="true">编号</th>
        <th field="dalei" width="30" align="center" sortable="true">大类</th>
        <th field="xiangmumingcheng" width="30" align="center" sortable="true">项目名称</th>
        <th field="wuliaobianma" width="50" align="center" sortable="true">物料编码</th>
        <th field="mingchengguige" width="50" align="center" sortable="true">名称规格</th>
        <th field="danwei" width="20" align="center" sortable="true">单位</th>
        <th field="chukushuliang" width="40" align="center" sortable="true">出库数量</th>
        <th field="tuikushuliang" width="40" align="center" sortable="true">退库数量</th>
        <th field="weituihuiliang" width="40" align="center" sortable="true">实际用量</th>
        <th field="chukukufang" width="30" align="center" sortable="true">出库库房</th>
        <th field="beizhu" width="30" align="center" sortable="true">备注</th>
        <th field="createtime" width="40" align="center" sortable="true">创建时间</th>
        <th field="zongzhangid" width="20" align="center" hidden="true" sortable="true">单价</th>
    </tr>
    </thead>
</table>

<div id="tb">
    <div style="padding-bottom: 5px">
        <fieldset style="border-color: #E7F0FF">
            <legend>参数设置</legend>
            <tr>
                <td>
                    &nbsp;出库单号：<input type="text" id="chukudanhaoinput" name="duiyingchukudanhao"  onkeydown="if(event.keyCode==13) search()"
                                      size="20"/>
                    &nbsp;项目选择：<input type="text" id="projName" name="xiangmumingcheng"
                                                        style="width: 90px;" readonly="readonly"
                                                        onclick="openProjListChoose()"/>
                    <input type="hidden" id="projId"/>
                    &nbsp;&nbsp;&nbsp;&nbsp;领料单位：<input type="text" id="deptName" name="bumenmingcheng" size="10"
                                                        readonly="readonly" onclick="openDeptListChoose()"
                                                        required="true"/>

                    <!--TODO 根据物料类别查用量(出库执行汇总)暂时没给做-->
                    <!--&nbsp;物料类别&nbsp;-->
                    <input type="hidden" id="o_id"/>
                    <!--<input type="text" id="typeName" style="width: 90px;" readonly="readonly"-->
                           <!--onclick="chooseGoodsType()"/>-->
                </td>
            </tr>

            <tr>
                <td>
                    &nbsp;物料名称：&nbsp;<input type="text" id="mingchengguige" size="20"
                                            onkeydown="if(event.keyCode==13) search()"/>
                    <br>
                    &nbsp;往来日期：
                    <input id="s_btime" class="easyui-datebox" editable=false style="width:100px">
                    &nbsp;&nbsp;-&nbsp;&nbsp;
                    <input id="s_etime" class="easyui-datebox" editable=false style="width:100px">
                    &nbsp;&nbsp;<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search"
                                   plain="true">搜索</a>
                </td>
            </tr>

        </fieldset>
    </div>
</div>


<div id="dlg2" class="easyui-dialog" style="width:180px;height:300px;padding: 10px 10px;top: 52px;left: 80px"
     closed="true" buttons="#dlg-buttons2">
    <ul id="typeTree" class="easyui-tree"></ul>
</div>

<div id="dlg-buttons2">
    <a href="javascript:saveGoodsTypeChoose()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">选择</a>
    <a href="javascript:closeGoodsTypeChooseDialog()" class="easyui-linkbutton" iconCls="icon-cancel"
       plain="true">关闭</a>
</div>

<!--查询项目列表-->
<div id="projList" class="easyui-dialog" style="width:800px;height:460px;"
     closed="true" data-options="onClose:function(){$('#s_codeOrProjName').val('');}">
    <div class="easyui-layout" style="width:100%;height:100%;">

        <div region="north" style="height: 50px;">
            <div style="padding-top: 8px;padding-left: 40px;">
                &nbsp;项目名称：&nbsp;<input type="text" id="projSearch" size="30"
                                              onkeydown="if(event.keyCode==13) searchProj()"/>
                <a href="javascript:searchProj()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            </div>
        </div>
        <div region="west" style="width: 200px" title="项目分类" split="true" data-options="collapsible:false">
            <div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
                <ul id="projTree" class="easyui-tree" style="padding: 10px"></ul>
            </div>
            <div style="position:absolute;bottom: 10px;left: 15px">
                <a href="javascript:saveProjChoose()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
                <!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
            </div>
        </div>
        <div region="center">
            <table id="projNameList" title="项目列表" class="easyui-datagrid"
                   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
                   url="/admin/dproject/getSelective" fit="true" toolbar="#tb4">
                <thead>
                <tr>
                    <th field="id" width="30" hidden=true align="center">编号</th>
                    <th field="xiangmumingcheng" width="150" align="center">项目名称</th>
                    <th field="createtime" width="90" align="left">创建时间</th>

                </tr>
                </thead>
            </table>
            <div id="tb4">
                <div>
                    <a href="javascript:saveProjChoose()" class="easyui-linkbutton" iconCls="icon-ok"
                       plain="true">选择</a>
                </div>
            </div>
        </div>
    </div>
</div>

<!--查询部门列表-->
<div id="deptList" class="easyui-dialog" style="width:800px;height:460px;"
     closed="true" data-options="onClose:function(){$('#s_codeOrDeptName').val('');}">
    <div class="easyui-layout" style="width:100%;height:100%;">

        <div region="north" style="height: 50px;">
            <div style="padding-top: 8px;padding-left: 40px;">
                &nbsp;部门名称：&nbsp;<input type="text" id="deptSearch" size="30"
                                              onkeydown="if(event.keyCode==13) searchDept()"/>
                <a href="javascript:searchDept()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            </div>
        </div>
        <div region="west" style="width: 200px" title="发料单位分类" split="true" data-options="collapsible:false">
            <div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
                <ul id="deptTree" class="easyui-tree" style="padding: 10px"></ul>
            </div>
            <div style="position:absolute;bottom: 10px;left: 15px">
                <a href="javascript:saveDeptChoose(1)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
                <!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
            </div>
        </div>
        <div region="center">
            <table id="deptNameList" title="发料单位列表" class="easyui-datagrid"
                   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
                   url="/admin/dbumen/getSelective" fit="true" toolbar="#tb-bm">
                <thead>
                <tr>
                    <th field="id" width="30" hidden=true align="center">编号</th>
                    <th field="bumenmingcheng" width="150" align="center">单位名称</th>
                    <th field="createtime" width="90" align="left">创建时间</th>
                </tr>
                </thead>
            </table>
            <div id="tb-bm">
                <div>
                    <a href="javascript:saveDeptChoose(2)" class="easyui-linkbutton" iconCls="icon-ok"
                       plain="true">选择</a>
                </div>
            </div>
        </div>
    </div>
</div>

<!--大屏幕上右键datagrid dlg-->
<div id="grid-data" class="easyui-menu" style="width: 80px; display: none;">
    <div id="grid-data-edit" href="javascript:openDetailsModifyDialog()" data-options="iconCls:'icon-edit'">修改</div>
    <div id="grid-data-delete" href="javascript:deleteDetails()" data-options="iconCls:'icon-remove'" plain="true">删除
    </div>
</div>
<!--二级菜单右键弹出-->
<div id="tree-2" class="easyui-menu" style="width: 80px; display: none;">
    <div id="tree-2-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除二级菜单</div>
</div>
<!--一级菜单右键弹出-->
<div id="tree-1" class="easyui-menu" style="width: 80px; display: none;">
    <div id="tree-1-add-2" href="javascript:openTypeAddDialog()" data-options="iconCls:'icon-add'">添加二级菜单</div>
    <div id="tree-1-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除一级菜单</div>
</div>
<!--树形菜单右键弹出-->
<div id="tree-0" class="easyui-menu" style="width: 80px; display: none;">
    <div id="tree-0-add-1" href="javascript:openTypeAddDialog(0)" data-options="iconCls:'icon-add'">添加一级菜单</div>
    <div id="tree-0-refresh" href="javascript:reloadTree()" data-options="iconCls:'icon-reload'">重新加载类别</div>
</div>


</body>
</html>